<template>
  <div class="oe-wrong-question" v-loading="loading">
    <top-tip :batchTitle="batchTitle" :examTitle="examTitle"></top-tip>

    <div class="oe-modal-table">
      <a-table
        :pagination="modalPagination"
        :position="center"
        :columns="modalErrorPageColumns"
        :dataSource="modalErrorPageList"
        :scroll="{ y: 470 }"
        @change="onModalChange"
        v-pic
      >
      <span slot="QuestionTitle" slot-scope="record,index">
        <div v-html="index.QuestionTitle"></div>
      </span>
      </a-table>
    </div>
  </div>
</template>

<script>
import topTip from '@/components/top-tip/index.vue';
import GetOperationList from '@/lib/mixin/methods.js';
export default {
  name: 'wrongStuList',
  mixins: [GetOperationList],
  components: {
    topTip
  },
  data() {
    return {
      loading: false,
      questionCount: 1,
      modalErrorPageList: [],
      letter: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
      q_type: [
        '',
        '单选题',
        '多选题',
        '判断',
        '客观填空题',
        '主观填空题',
        '问答题',
        '匹配题',
        '客观阅读理解',
        '客观完形填空',
        '文件作答题',
        '视听题',
        '主观阅读理解',
        '主观完形填空',
      ],
      // 分页配置
      modalPagination: {
        pageSizeOptions: ['10', '20', '50', '100', '1000'],
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.modalPagination.current = current;
          this.modalPagination.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          this.modalPagination.current = current;
          this.modalPagination.pageSize = pageSize;
        },
        buildOptionText(props) {
          return props.value + '条/页';
        },
        current: 1,
        pageSize: 10,
        total: 0
      },

      //错题统计
      questionTypeList: [
        {
          value: 1,
          name: '单选题'
        },
        {
          value: 2,
          name: '多选题'
        },
        {
          value: 3,
          name: '判断题'
        },
        {
          value: 5,
          name: '填空题'
        },
        {
          value: 6,
          name: '问答题'
        },
        {
          value: 7,
          name: '匹配题'
        },
        {
          value: 8,
          name: '阅读理解'
        },
        {
          value: 9,
          name: '完形填空'
        },
        {
          value: 11,
          name: '视听题'
        }
      ],
      modalErrorPageColumns: [
        {
          title: '序号',
          dataIndex: 'number',
          key: 'number'
        },
        {
          title: '类型',
          dataIndex: 'QType',
          key: 'QType'
        },
        {
          title: '题干',
          dataIndex: 'QuestionTitle',
          key: 'QuestionTitle',
          ellipsis: true,
          scopedSlots: { customRender: 'QuestionTitle' },
        },

        {
          title: '分数',
          dataIndex: 'Score',
          key: 'Score'
        },
        {
          title: '正确人数',
          dataIndex: 'RightAnswerNum',
          key: 'RightAnswerNum'
        },
        {
          title: '错误人数(未作答人数)',
          dataIndex: 'kWrongAnswerNum',
          key: 'kWrongAnswerNum'
        },
        {
          title: '半对半错人数',
          dataIndex: 'HalfAnswerNum',
          key: 'HalfAnswerNum'
        },

        {
          title: '正确人数占比',
          dataIndex: 'kRightAnswerPer',
          key: 'kRightAnswerPer'
        },
        {
          title: '错误人数占比(未作答人数占比)',
          dataIndex: 'kWrongAnswerPer',
          key: 'kWrongAnswerPer'
        },
        {
          title: '半对半错人数占比',
          dataIndex: 'kHalfAnswerPer',
          key: 'kHalfAnswerPer'
        },
        {
          title: '未批阅人数',
          dataIndex: 'NoMarkedStuCount',
          key: 'NoMarkedStuCount'
        }
      ],
      examTitle:'',
      batchTitle:'',
    };
  },
  props: {
    examid: {
      type: String,
      default: ''
    },
    searchExamStruct: {
      type: String,
      default: ''
    }
  },
  mounted() {
    this.getPaperQuestionStuAnswerList();
    this.getOperation()
  },
  methods: {
    getOperation() {
      this.loading = true;
      this.GetOperationList('examId',this.examid).then((rst) => {
        this.loading = false;
        if (rst.code === 1) {
          this.examTitle = rst.examTitle
          this.batchTitle = rst.batchTitle
        } else {
          this.$message.error(rst.msg);
        }
      });
    },
    // 点击table排序
    onModalChange(pagenation, filter, sort) {
      this.getPaperQuestionStuAnswerList();
    },

    answerConversion(val) {
      var that = this,
        letter2 = ['错误', '正确'],
        key = '未作答';

      switch (Number(val.QuestionType)) {
        case 1:
          debugger;
          key = that.letter[Number(val.Answer)];
          break;
        case 2:
          var an_a = val.Answer.split(','),
            lett = [];
          an_a.forEach((item) => {
            lett.push(that.letter[item]);
          });

          key = lett.join(',');
          break;
        case 3:
          key = letter2[Number(val.Answer)];
          break;
        case 5:
          key = val.Answer;
          break;
        case 7:
          debugger;
          break;
        default:
          key = '--';
          break;
      }

      return key;
    },
    QuestionTypeConversion(val) {
      return val.QuestionType ? this.q_type[val.QuestionType] : '';
    },

    getPaperQuestionStuAnswerList() {
      this.loading = true;
      var that = this;

      this.$http
        .post('/api/examStatistics/examanaly/getPaperErrorQuesStaticList', {
          examId: this.examid,
          examStruct: this.searchExamStruct,
          pageSize: this.modalPagination.pageSize,
          page: this.modalPagination.current,
          isPaging: true
        })
        .then((res) => {
          this.loading = false;
          if (res.code > 0) {
            this.modalErrorPageList = [];

            res.list.forEach((item) => {
              let number = item.Index,
                kHalfAnswerPer = item.HalfAnswerPer + '%',
                kWrongAnswerPer = item.WrongAnswerPer + '%(' + item.NothingAnswerPer + '%)',
                kRightAnswerPer = item.RightAnswerPer + '%',
                kWrongAnswerNum = item.WrongAnswerNum + '(' + item.NothingAnswerNum + ')',
                qType = this.q_type[item.QuestionType];

              this.modalErrorPageList.push({
                ...item,
                number: number,
                QType: qType,
                kWrongAnswerNum: kWrongAnswerNum,
                kHalfAnswerPer: kHalfAnswerPer,
                kWrongAnswerPer: kWrongAnswerPer,
                kRightAnswerPer: kRightAnswerPer
              });
            });
            this.modalPagination.current = res.pagination.pageIndex;
            this.modalPagination.pageSize = res.pagination.pageSize;
            this.modalPagination.total = res.pagination.totalCount;
          } else {
            this.$message.warning(res.msg);
          }
        });
    }
  },
};
</script>

<style lang="scss">
.oe-wrong-question {
  margin-top: 20px;

  width: 100%;
  background: #fff;
  border-radius: 5px;
}
</style>
